const db = uniCloud.database();

var recipe={
	pageQueryRecipe:async (page=1)=>{
		const totalRes=await db.collection('recipe').count();
		const total = totalRes.total;
		const totalPage = Math.ceil(total / 10);
		let hasMore=true;
		if(page>=totalPage){
			hasMore=false;
		}
		const dataRes=await db.collection('recipe').skip((page-1)*10).limit(10).get();
		let list=dataRes.data;
		console.log(list)
		return {hasMore:hasMore,list:list};
	},
	queryRecipeInfoByRecipeCode:(recipe_code)=>{
		let recipe=db.collection('recipe')
		.where({recipe_code:recipe_code}).get();
		return recipe;
	},
	queryRecipeIngredientsByRecipeCode:(recipe_code)=>{
		let recipe_ingredients=db.collection('recipe_ingredient')
		.where({recipe_code:recipe_code}).orderBy("seq", "asc").get();
		return recipe_ingredients;
	},
	queryRecipeStepsByRecipeCode:(recipe_code)=>{
		let recipe_steps=db.collection('recipe_step')
		.where({recipe_code:recipe_code}).orderBy("step_seq", "asc").get();
		return recipe_steps;
	}
}

module.exports = recipe;

